import axios from 'axios'
async function request<T>(method: string, url: string, data?: any) {
    if (data instanceof FormData) {
        let res = await axios.post(url,data)
        let json : T = await res.data
        return json
    } else {
       let res = await axios({
           url:url,
           method : 'post',
           headers:{'Content-type': 'application/json; charset=utf-8'},
           data :JSON.stringify(data)
       })
       let json :T = await res.data
       return json
    }
 }  
  export function get<T>(url: string) {
    return request<T>('GET', url)
  }
  
  export function post<T>(url: string, data?: any) {
    return request<T>('POST', url, data)
  }